// Project: XnaGraphicEngine, File: Sound.cs
// Namespace: XnaGraphicEngine.Sounds, Class: Sound
// Path: \XnaGraphicEngine\Sounds
// Author: XXX 666
// Code lines: 232
// Creation date: 07.12.2006 18:22
// Last modified: 07.12.2006 22:29

#region Using directives
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Media;

using Xeno_Race.Graphics;
#endregion

namespace Xeno_Race.SoundManager
{
    public class Sound
    {
        #region Sound arrays
        private Song[] musiclist;
        private SoundEffect[] soundlist;
        #endregion

        #region Enums
        /// <summary>
        /// Sounds we use in this game.
        /// </summary>
        /// <returns>Enum</returns>
        public enum Sounds
        {
            AfterBurner,
            AlienScanner,
            boom,
            car_going,
            Click,
            Comet,
            CrashBurn,
            Earthquake,
            Engine,
            Fasten_Your_Seat_Belt,
            hotidle,
            MenuMusic,
            revitup,
            Spacecraft_Start_Engines,
            Spacejet_Z_Wing_InFlight,
            SpaceWhoosh,
            turbine_idle,

            //add more later
        } // enum Sounds

        public enum Music
        {
            Enigma_Endless_quest,
        }
        #endregion

        #region Play
        /// <summary>
        /// Play
        /// </summary>
        /// <param name="soundName">Sound name</param>
        public void LoadMenuSounds(ContentManager content)
        {
            string dir = "content//sounds//";
            musiclist = new Song[]
            {
                content.Load<Song> (dir + "Enigma_Endless_quest")
            };
            SoundEffect click = content.Load<SoundEffect>(dir + "Click");
            click.Name = "Click";
            SoundEffect turbine_idle = content.Load<SoundEffect>(dir + "spaceship_engine");
            turbine_idle.Name = "turbine_idle";
            soundlist = new SoundEffect[]
            {
                click,
                turbine_idle
            };
            //repeat above 2 lines to add each sound effect.
            //soundlist = new SoundEffect[]{ click, next object name, next,next};
        }

        #endregion

        #region PlaySoundEffect
        private void PlaySoundEffect(string sound, float volume, float pitch, bool repeat)
        {
            for (int t = 0; t < soundlist.Length; t++)
            {
                if (soundlist[t].Name.Contains(sound))
                {
                    soundlist[t].Play(volume, pitch, 0.0f, repeat);
                    break;
                }
            }
        }
        #endregion

        #region PlayMusic
        private void PlayMusic(string music)
        {
            for (int t = 0; t < musiclist.Length; t++)
            {
                if (musiclist[t].ToString().Contains(music))
                {
                    if (MediaPlayer.State != MediaState.Playing)
                        MediaPlayer.Play(musiclist[t]);
                    break;
                }
            }
        }
        #endregion

        /// <summary>
        /// Returns the specified sound as a paused but playable SoundEffectInstance
        /// </summary>
        /// <param name="sound">Name of the Sound to be returend</param>
        public SoundEffectInstance getSoundEffect(Sounds sound)
        {
            for (int t = 0; t < soundlist.Length; t++)
            {
                if (soundlist[t].Name.Contains(sound.ToString()))
                {
                    SoundEffectInstance getEffect = soundlist[t].Play(0.0f, 0.0f, 0.0f, true);
                    getEffect.Pause();
                    return getEffect;
                }
            }
            return null;
        }

        public void play(Sounds sound)
        {
            PlaySoundEffect(sound.ToString(), 1.0f, 0.0f, false);
        }

        public void play(Sounds sound, float volume, float pitch, bool repeat)
        {
            PlaySoundEffect(sound.ToString(), volume, pitch, repeat);
        }

        public void play(Music menumusic)
        {
            PlayMusic(menumusic.ToString());
        }

        public void stopMusic()
        {
            MediaPlayer.Stop();
        }
    }
}